﻿using System;

namespace System.Data.Linq.Mapping
{
    /// <summary>
    /// Replicates just enough of LINQ to SQL to allow source compatibility with the non-Metro framework to associates a class with a column in a database table.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
    public sealed class ColumnAttribute : Attribute
    {
        public ColumnAttribute() { }

        /// <summary>
        /// Whether the field would autosync on update
        /// </summary>
        public AutoSync AutoSync { get; set; }

        /// <summary>
        /// Whether the column can contain NULL values
        /// </summary>
        public bool CanBeNull { get; set; }

        /// <summary>
        /// The native type for the database column
        /// </summary>
        public string DbType { get; set; }

        /// <summary>
        /// Whether a column is computed in the database
        /// </summary>
        public string Expression { get; set; }

        /// <summary>
        /// Whether the column is auto-generated by the database
        /// </summary>
        public bool IsDbGenerated { get; set; }

        /// <summary>
        /// Whether a column contains a discriminator value for SQL inheritence
        /// </summary>
        public bool IsDiscriminator { get; set; }

        /// <summary>
        /// Whether this class member represents a column that is part (or all) of the primary key for the table
        /// </summary>
        public bool IsPrimaryKey { get; set; }

        /// <summary>
        /// Whether the column type of the member is a database timestamp
        /// </summary>
        public bool IsVersion { get; set; }

        /// <summary>
        /// Used for assisting with optimistic concurrency conflicts
        /// </summary>
        public UpdateCheck UpdateCheck { get; set; }

        /// <summary>
        /// The Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// The name of the storage field.
        /// </summary>
        public string Storage { get; set; }
    }

    public enum AutoSync
    {
        /// <summary>
        /// Automatically selects the value.
        /// </summary>
        Default = 0,

        /// <summary>
        /// Always returns the value.
        /// </summary>
        Always = 1,
        
        /// <summary>
        /// Never returns the value.
        /// </summary>
        Never = 2,
        
        /// <summary>
        /// Returns the value only after an insert operation.
        /// </summary>
        OnInsert = 3,
        
        /// <summary>
        /// Returns the value only after an update operation.
        /// </summary>
        OnUpdate = 4,
    }

    /// <summary> 
    /// Specifies when objects are to be tested for concurrency conflicts.
    /// </summary>
    public enum UpdateCheck
    {
        /// <summary>
        /// Always check
        /// </summary>
        /// <remarks>LINQ doesn't check if IsVersion is true</remarks>
        Always = 0,

        /// <summary>
        /// Never check
        /// </summary>
        Never = 1,

        /// <summary>
        /// Check when changed
        /// </summary>
        WhenChanged = 2,
    }
}

